//
//  KZResultView.m
//  听说弱点强化训练
//
//  Created by 朱凯 on 2018/8/24.
//  Copyright © 2018年 盛超. All rights reserved.
//

#import "KZResultView.h"

@implementation KZResultView
{
    UIView      *_bgView;
    UIImageView *_iconView;
    UILabel     *_statusLabel;
    UILabel     *_noteLabel;
}

- (instancetype)init {
    
    if (self = [super init]) {
        
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    
    _bgView = [UIView new];
    _bgView.layer.cornerRadius = 4;
    [self addSubview:_bgView];
    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@0);
        make.centerX.equalTo(@0);
        make.height.equalTo(@35);
        // 宽度子视图决定
    }];
    
    _iconView = [UIImageView new];
    [_bgView addSubview:_iconView];
    [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.centerY.equalTo(@0);
    }];
    
    _statusLabel = [[UILabel alloc] init];
    _statusLabel.text = @"";
    _statusLabel.font = FONT(13);
    _statusLabel.textAlignment = NSTextAlignmentCenter;
    _statusLabel.textColor = [UIColor whiteColor];
    [_bgView addSubview:_statusLabel];
    [_statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_iconView.mas_right).offset(5);
        make.right.equalTo(@-10);
        make.centerY.equalTo(@0);
    }];
    
    _noteLabel = [[UILabel alloc] init];
    _noteLabel.text = @"";
    _noteLabel.font = FONT(13);
    _noteLabel.textAlignment = NSTextAlignmentCenter;
    _noteLabel.textColor = [UIColor lightGrayColor];
    [self addSubview:_noteLabel];
    [_noteLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.height.equalTo(@15);
        make.top.equalTo(_bgView.mas_bottom).offset(5);
    }];
}

- (void)setStatus:(NSInteger)status {
    
    _status = status;
    
    switch (_status) {
        case 0: // 成功
        {
            _bgView.backgroundColor = RGBA(117, 196, 93, 1);
            _iconView.image = [UIImage imageNamed:@"kz-success"];
            _statusLabel.text = @"Well done!";
            _statusLabel.textColor = UIColor.whiteColor;
            _noteLabel.hidden = false;
            _noteLabel.text = @"  正在进入下一个音标，请准备...";
        }
            break;
        case 10: // 成功3
        {
            _bgView.backgroundColor = RGBA(117, 196, 93, 1);
            _iconView.image = [UIImage imageNamed:@"kz-success"];
            _statusLabel.text = @"Well done!";
            _statusLabel.textColor = UIColor.whiteColor;
            _noteLabel.hidden = false;
            _noteLabel.text = @"";
        }
            break;
        case 1: // 失败1
        {
            _bgView.backgroundColor = RGBA(215, 127, 72, 1);
            _iconView.image = [UIImage imageNamed:@"kz-failure"];
            _statusLabel.text = @"Try again!";
            _statusLabel.textColor = UIColor.whiteColor;
            _noteLabel.hidden = false;
            _noteLabel.text = @"  再复读1遍，请准备...";
        }
            break;
        case 2: // 失败2
        {
            _bgView.backgroundColor = RGBA(234, 190, 161, 0.6);
            _iconView.image = [UIImage imageNamed:@"kz-final-failure"];
            _statusLabel.text = @"不合格!";
            _statusLabel.textColor = [UIColor colorWithHex:0xFF2A00];
            _noteLabel.hidden = true;
        }
            break;
        case 3: // 成功2
        {
            _bgView.backgroundColor = RGBA(117, 196, 93, 1);
            _iconView.image = [UIImage imageNamed:@"kz-success"];
            _statusLabel.text = @"合格!";
            _statusLabel.textColor = UIColor.whiteColor;
            _noteLabel.hidden = true;
        }
            break;
        default:
            break;
    }
    
}
@end
